package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserOrderAppeal;
import com.happy.cat.project.system.service.IUserOrderAppealService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户订单申诉Controller
 *
 * @author verne
 * @date 2020-08-13
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userOrderAppeal" )
@Api("用户订单申诉 API")
public class UserOrderAppealController extends BaseController {

    private final IUserOrderAppealService iUserOrderAppealService;

    /**
     * 查询用户订单申诉列表
     */
    @ApiOperation(value = "查询用户订单申诉列表",notes = "查询用户订单申诉列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderAppeal:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserOrderAppeal userOrderAppeal)
    {
        startPage();
        LambdaQueryWrapper<UserOrderAppeal> lqw = new LambdaQueryWrapper<UserOrderAppeal>();
        if (StringUtils.isNotBlank(userOrderAppeal.getCode())){
            lqw.eq(UserOrderAppeal::getCode ,userOrderAppeal.getCode());
        }
        if (StringUtils.isNotBlank(userOrderAppeal.getOrderCode())){
            lqw.eq(UserOrderAppeal::getOrderCode ,userOrderAppeal.getOrderCode());
        }
        if (userOrderAppeal.getUserId() != null){
            lqw.eq(UserOrderAppeal::getUserId ,userOrderAppeal.getUserId());
        }
        if (StringUtils.isNotBlank(userOrderAppeal.getReason())){
            lqw.eq(UserOrderAppeal::getReason ,userOrderAppeal.getReason());
        }
        if (StringUtils.isNotBlank(userOrderAppeal.getScreenshot())){
            lqw.eq(UserOrderAppeal::getScreenshot ,userOrderAppeal.getScreenshot());
        }
        if (userOrderAppeal.getStatus() != null){
            lqw.eq(UserOrderAppeal::getStatus ,userOrderAppeal.getStatus());
        }
        if (userOrderAppeal.getDealTime() != null){
            lqw.eq(UserOrderAppeal::getDealTime ,userOrderAppeal.getDealTime());
        }
        List<UserOrderAppeal> list = iUserOrderAppealService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户订单申诉列表
     */
    @ApiOperation(value = "导出用户订单申诉列表",notes = "导出用户订单申诉列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderAppeal:export')" )
    @Log(title = "用户订单申诉" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserOrderAppeal userOrderAppeal) {
        LambdaQueryWrapper<UserOrderAppeal> lqw = new LambdaQueryWrapper<UserOrderAppeal>(userOrderAppeal);
        List<UserOrderAppeal> list = iUserOrderAppealService.list(lqw);
        ExcelUtil<UserOrderAppeal> util = new ExcelUtil<UserOrderAppeal>(UserOrderAppeal. class);
        return util.exportExcel(list, "userOrderAppeal" );
    }

    /**
     * 获取用户订单申诉详细信息
     */
    @ApiOperation(value = "获取用户订单申诉详细信息",notes = "获取用户订单申诉详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderAppeal:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserOrderAppealService.getById(id));
    }

    /**
     * 新增用户订单申诉
     */
    @ApiOperation(value = "新增用户订单申诉",notes = "新增用户订单申诉",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderAppeal:add')" )
    @Log(title = "用户订单申诉" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserOrderAppeal userOrderAppeal) {
        return toAjax(iUserOrderAppealService.save(userOrderAppeal) ? 1 : 0);
    }

    /**
     * 修改用户订单申诉
     */
    @ApiOperation(value = "修改用户订单申诉",notes = "修改用户订单申诉",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderAppeal:edit')" )
    @Log(title = "用户订单申诉" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserOrderAppeal userOrderAppeal) {
        return toAjax(iUserOrderAppealService.updateById(userOrderAppeal) ? 1 : 0);
    }

    /**
     * 删除用户订单申诉
     */
    @ApiOperation(value = "删除用户订单申诉",notes = "删除用户订单申诉",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOrderAppeal:remove')" )
    @Log(title = "用户订单申诉" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserOrderAppealService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
